import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:osg/controllers/http.dart';
import 'package:photo_view/photo_view.dart';
import 'package:photo_view/photo_view_gallery.dart';


final RxInt isdata = 1.obs;
final RxInt _index = 0.obs;
final RxInt followPage = 1.obs;
final RxInt articlePage = 1.obs;
final RxList followArticleData = [].obs;
final RxList articleData = [].obs;
final RxList hotTopicData = [].obs;
final RxBool isLoading = false.obs;

  

getFollowArticle() {
  Get.find<HTTPS>().nogetData(
      '/bbs/followArticle', {'page': '${followPage.value}'}).then((res) {
    if (res != null) {
      isLoading.value = false;
      for (var item in res) {
        articleData.add(item);
      }
    }
  });
}

getArticle() {
  Get.find<HTTPS>()
      .getData('/bbs/article', {'page': '${articlePage.value}'}).then((res) {
    if (res != null) {
      isdata.value = res.length;
      isLoading.value = false;
      for (var item in res) {
        articleData.add(item);
      }
    }
  });
}

gethotTopic() {
  Get.find<HTTPS>().getData('/bbs/hotTopic', {}).then((res) {
    if (res != null) {
      hotTopicData.value = res.take(4).toList();
    }
  });
}

class FindLIst extends StatefulWidget {
  const FindLIst({super.key});
  @override
  State<FindLIst> createState() => _FindLIst();
}

class _FindLIst extends State<FindLIst> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  loadMore() {
    if (isLoading.value) return;
    isLoading.value = true;
    articlePage.value++;
    if (_index.value == 1 || _index.value == 0) {
      getArticle();
    }
  }

  @override
  Widget build(BuildContext context) {
    WidgetsBinding.instance.addPostFrameCallback((_) {
      getFollowArticle();
    });

// 总高度 = 状态栏高度 + AppBar 内容高度
//final totalHeight = MediaQuery.of(context).padding.top + kToolbarHeight;
    final Height = MediaQuery.of(context).padding.top + 15;
    return Scaffold(
        body: NotificationListener<ScrollNotification>(
      onNotification: (notification) {
        // 判断是否滚动到底部（距离底部还有 100 像素时触发）
        if (notification.metrics.pixels >=
            notification.metrics.maxScrollExtent - 0) {
          if (isdata.value > 0) {
            loadMore();
          }

          // 执行分页加载逻辑
        }
        return true;
      },
      child: ListView(children: [
        SizedBox(height: 10),
        TopDynamic(),
        SearchBar(),
        Obx(
          () => _index.value == 1 ? Card() : SizedBox(),
        ),
        SizedBox(height: 15),
        Obx(() => _index.value == 1 || _index.value == 0
            ? NotificationLayout()
            : task())
      ]),
    ));
  }
}

class GradientLinearProgress extends StatelessWidget {
  final double progress;
  final double height;

  const GradientLinearProgress({
    Key? key,
    required this.progress,
    this.height = 8.0,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: height,
      child: Stack(
        children: [
          // 背景层
          Container(
            decoration: BoxDecoration(
              color: Color(0XFFead5fd),
              borderRadius: BorderRadius.circular(height / 2),
            ),
          ),
          // 渐变进度层
          ClipRRect(
            borderRadius: BorderRadius.circular(height / 2),
            child: Align(
              alignment: Alignment.centerLeft,
              child: Container(
                width: MediaQuery.of(context).size.width *
                    progress *
                    0.5, // 调整宽度系数
                height: height,
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [Color(0xff2189E7), Color(0xffBF67F8)],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}

void _openGallery(BuildContext context, int initialIndex,imageUrls) {
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => GalleryView(
          images: imageUrls,
          initialIndex: initialIndex,
        ),
      ),
    );
}


Widget task() {
  List<Map> items = [
    {'text': "个人资料", "index": 0},
    {'text': "安全设置", "index": 1},
    {'text': "关于OSG", "index": 2},
  ];
  // for (var item in items)

  return Container(
    margin: EdgeInsets.symmetric(horizontal: 15),
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset(
              'static/images/ren.png',
              width: 15,
              fit: BoxFit.fitWidth,
            ),
            SizedBox(
              width: 5,
            ),
            Text(
              'OSG公海云集视频计划！',
              style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold),
            )
          ],
        ),
        SizedBox(
          height: 10,
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.asset(
              'static/images/ren.png',
              width: 15,
              fit: BoxFit.fitWidth,
            ),
            SizedBox(
              width: 5,
            ),
            Text(
              'OSG公海云集优质动态萌芽计划！',
              style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold),
            )
          ],
        ),
        SizedBox(
          height: 20,
        ),
        // Row(
        //   crossAxisAlignment: CrossAxisAlignment.center,
        //   children: [
        //     Image.asset(
        //       'static/images/ren.png',
        //       width: 15,
        //       fit: BoxFit.fitWidth,
        //     ),
        //     SizedBox(
        //       width: 5,
        //     ),
        //     Text(
        //       '征集令人心动可爱瞬间',
        //       style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold),
        //     )
        //   ],
        // ),
        // SizedBox(
        //   height: 20,
        // ),
        Image.asset(
          'static/dating.png',
          width: 80,
          fit: BoxFit.fitWidth,
        ),
        Container(
          alignment: Alignment.center,
          margin: EdgeInsets.only(top: 50),
          child: ClipRRect(
            borderRadius: BorderRadius.circular(15.0),
            child: Image.asset(
              'static/qidai.png',
              width: 250,
              fit: BoxFit.fitWidth,
            ),
          ),
        ),
        for (var item in [])
          Container(
              margin: EdgeInsets.only(top: 10),
              decoration: BoxDecoration(
                border: Border.all(color: Color(0XFFDDDDDD)),
                borderRadius: BorderRadius.circular(10),
              ),
              child: Column(
                children: [
                  Padding(
                    padding: EdgeInsets.all(10),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        ClipRRect(
                          borderRadius: BorderRadius.circular(5.0), // 设置圆角大小
                          child: Image.asset(
                            'static/aaa.png',
                            width: 60,
                            height: 80,
                            fit: BoxFit.fill,
                          ),
                        ),
                        SizedBox(
                          width: 10,
                        ),
                        Expanded(
                            child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              'OSG公海云集视频计划！',
                              style: TextStyle(
                                  fontSize: 16, fontWeight: FontWeight.bold),
                            ),
                            SizedBox(
                              height: 5,
                            ),
                            Row(
                              children: [
                                Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 2, horizontal: 10),
                                  color: Color(0XFFE2F0FF),
                                  child: Text(
                                    '转发',
                                    style: TextStyle(fontSize: 12),
                                  ),
                                ),
                                SizedBox(
                                  width: 10,
                                ),
                                Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 2, horizontal: 10),
                                  color: Color(0XFFFFD7D7),
                                  child: Text(
                                    '点赞',
                                    style: TextStyle(fontSize: 12),
                                  ),
                                ),
                                SizedBox(
                                  width: 10,
                                ),
                                Container(
                                  padding: EdgeInsets.symmetric(
                                      vertical: 2, horizontal: 10),
                                  color: Color(0XFFEDE4FD),
                                  child: Text(
                                    '评论',
                                    style: TextStyle(fontSize: 12),
                                  ),
                                ),
                              ],
                            ),
                            SizedBox(
                              height: 10,
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Row(
                                  children: [
                                    Text(
                                      '+233',
                                      style: TextStyle(
                                          fontSize: 15,
                                          color: Color(0XFFEF0000)),
                                    ),
                                    SizedBox(
                                      width: 5,
                                    ),
                                    Text(
                                      'st',
                                      style: TextStyle(fontSize: 10),
                                    )
                                  ],
                                ),
                                GestureDetector(
                                    onTap: () =>
                                        {Get.toNamed('/talk/task_detail')},
                                    child: Image.asset(
                                      'static/images/jiedan.png',
                                      width: 28,
                                      fit: BoxFit.fitWidth,
                                    ))
                              ],
                            )
                          ],
                        )),
                      ],
                    ),
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: Container(
                            padding: EdgeInsets.symmetric(horizontal: 15),
                            height: 40,
                            color: Color(0XFFf2f1fe),
                            child: Row(
                              children: [
                                Text('奖励已发放 8%'),
                                SizedBox(
                                  width: 10,
                                ),
                                Expanded(
                                  child: GradientLinearProgress(progress: 0.7),
                                )
                              ],
                            )),
                      )
                    ],
                  )
                ],
              )),
      ],
    ),
  );
}
class NotificationLayout extends StatelessWidget {
  const NotificationLayout({super.key});

  @override
  Widget build(BuildContext context) {
    final width = MediaQuery.of(context).size.width / 3.4;
    return Obx(() => Column(
          children: [

            if(articleData.isEmpty) Container(
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 100),
      child: Text('暂无数据',
          style: TextStyle(fontSize: 16, color: Color(0XFF999999))),
    ),

            for (int i = 0; i < articleData.length; i++)
              Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(left: 15, right: 15, top: 20),
                    child:  Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                CircleAvatar(
                                  radius: 24,
                                  backgroundImage:
                                  NetworkImage(
                                      '${articleData[i]['headimg']}',
                                  )
                                  // child: Image.network(
                                  //     '${articleData[i]['headimg']}',
                                  //     errorBuilder:
                                  //         (context, error, stackTrace) {
                                  //   return SizedBox(
                                  //     width: 48,
                                  //   );
                                  // }),
                                ),
                                SizedBox(width: 8),
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                      '${articleData[i]['name']}',
                                      style: TextStyle(
                                          fontSize: 16,
                                          fontWeight: FontWeight.bold),
                                    ),
                                    SizedBox(height: 4),
                                    Text(
                                      '${articleData[i]['time']}',
                                      style: TextStyle(
                                          fontSize: 12, color: Colors.grey),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                            SizedBox(height: 10),
                            Text(
                              '${articleData[i]['text']}',
                              style: TextStyle(
                                  fontSize: 14, color: Color(0xff333333)),
                            ),
                            SizedBox(height: 10),
                            Wrap(
                              spacing: 5,
                              runSpacing: 5,
                              children: [

                                for (var item in articleData[i]['images'].asMap().entries)
                                 articleData[i]['images'].length>1?
                                 GestureDetector(
                                  onTap: (){
                                    _openGallery(context, item.key,articleData[i]['images']
                                    );
                                  },
                                  child: ClipRRect(
                                      borderRadius: BorderRadius.circular(5),
                                      child: Image.network(item.value,
                                          width: width,
                                          height: width,
                                          fit: BoxFit.fill, errorBuilder:
                                              (context, error, stackTrace) {
                                        return SizedBox(
                                          width: width,
                                          height: width,
                                        );
                                      }))
                                  , )
                                      :
                                       GestureDetector(
                                  onTap: (){
                                    _openGallery(context, item.key,articleData[i]['images']
                                    );
                                  },
                                  child:
                                      ClipRRect(
                                      borderRadius: BorderRadius.circular(5),
                                      child: Image.network(item.value,
                                           width: 150,
                                          fit: BoxFit.cover, errorBuilder:
                                              (context, error, stackTrace) {
                                        return SizedBox(
                                          width: width,
                                          height: width,
                                        );
                                      })
                                      ),
                                      ),
                              ],
                            ),
                            Container(
                              margin: EdgeInsets.only(top: 10, bottom: 10),
                              padding: EdgeInsets.only(
                                  top: 1, bottom: 1, right: 10, left: 10),
                              decoration: BoxDecoration(
                                color: Color(0xffF3EEFF),
                                borderRadius: BorderRadius.circular(10.0),
                              ),
                              child: Text(
                                '# ${articleData[i]['topic']}',
                                style: TextStyle(fontSize: 12),
                              ),
                            ),
                          ]),
                    
                  ),
                  Container(
                    margin: EdgeInsets.only(left: 15, right: 15),
                    child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Image.asset(
                                'static/images/share.png',
                                width: 15,
                              ),
                              Text(''),
                            ],
                          ),
                          // if (!articleData[i]['is_down'] &&
                          //     !articleData[i]['is_up'])
                          //   Row(
                          //     children: [
                          //       GestureDetector(
                          //         onTap: () {
                          //           Get.find<HTTPS>().postData('/bbs/updown', {
                          //             "article_id": articleData[i]['id'],
                          //             "type": 1,
                          //           }).then((res) {
                          //             if (res != null) {
                          //               articleData[i]['is_up'] = res['is_up'];
                          //               articleData[i]['up_count'] =
                          //                   res['up_count'];
                          //               articleData.refresh();
                          //             }
                          //           });
                          //         },
                          //         child: Row(
                          //           children: [
                          //             Image.asset(
                          //               'static/images/hongxin.png',
                          //               width: 15,
                          //             ),
                          //             Text('${articleData[i]['up_count']}'),
                          //           ],
                          //         ),
                          //       ),
                          //       SizedBox(
                          //         width: 70,
                          //       ),
                          //       GestureDetector(
                          //         onTap: () {
                          //           Get.find<HTTPS>().postData('/bbs/updown', {
                          //             "article_id": articleData[i]['id'],
                          //             "type": 2,
                          //           }).then((res) {
                          //             if (res != null) {
                          //               articleData[i]['is_down'] =
                          //                   res['is_down'];
                          //               articleData[i]['down_count'] =
                          //                   res['down_count'];
                          //               articleData.refresh();
                          //             }
                          //           });
                          //         },
                          //         child: Row(
                          //           children: [
                          //             Image.asset(
                          //               articleData[i]['is_down']
                          //                   ? 'static/images/liekai.png'
                          //                   : 'static/images/aixin.png',
                          //               width: 15,
                          //             ),
                          //             Text('${articleData[i]['down_count']}'),
                          //           ],
                          //         ),
                          //       ),
                          //     ],
                          //   ),

                            GestureDetector(
                              onTap: () {
                                if(articleData[i]['is_down']==true){
                                  Get.find<HTTPS>().showTost('请先取消踩');
                                  return;
                                }
                                if(articleData[i]['is_up'] == false){
                                Get.find<HTTPS>().postData('/bbs/updown', {
                                  "article_id": articleData[i]['id'],
                                  "type": 1,
                                }).then((res) {
                                  if (res != null) {
                                    articleData[i]['is_up'] = res['is_up'];
                                    articleData[i]['up_count'] =
                                        res['up_count'];
                                    articleData.refresh();
                                  }
                                });
                                }else{

                                Get.find<HTTPS>().postData('/bbs/unUpdown', {
                                  "article_id": articleData[i]['id'],
                                  "type": 1,
                                }).then((res) {
                                  if (res != null) {
                                    articleData[i]['is_up'] = res['is_up'];
                                    articleData[i]['up_count'] =
                                        res['up_count'];
                                    articleData.refresh();
                                  }
                                });
                                }
                              },
                              child: Row(
                                children: [
                                  Image.asset(
                                    articleData[i]['is_up']?
                                    'static/images/hongxin.png':
                                    'static/images/aixin.png',
                                    width: 15,
                                  ),
                                  Text('${articleData[i]['up_count']}'),
                                ],
                              ),
                            ),



                            GestureDetector(
                              onTap: () {
                                if(articleData[i]['is_up']==true){
                                  Get.find<HTTPS>().showTost('请先取消赞');
                                  return;
                                }
                                if(articleData[i]['is_down'] == true){
                                    Get.find<HTTPS>().postData('/bbs/unUpdown', {
                                  "article_id": articleData[i]['id'],
                                  "type": 2,
                                }).then((res) {
                                    if (res != null) {
                                      articleData[i]['is_down'] = res['is_down'];
                                      articleData[i]['down_count'] =
                                          res['down_count'];
                                      articleData.refresh();
                                    }
                                  });
                                }else{
                                  Get.find<HTTPS>().postData('/bbs/updown', {
                                    "article_id": articleData[i]['id'],
                                    "type": 2,
                                  }).then((res) {
                                    if (res != null) {
                                      articleData[i]['is_down'] = res['is_down'];
                                      articleData[i]['down_count'] =
                                          res['down_count'];
                                      articleData.refresh();
                                    }
                                  });
                                }
                               
                              },
                              child: Row(
                                children: [
                                  Image.asset(
                                     'static/images/liekai.png',
                                    width: 15,
                                  ),
                                  Text('${articleData[i]['down_count']}'),
                                ],
                              ),
                            ),




                          GestureDetector(
                            onTap: () {
                              Get.toNamed(
                            '/talk/deatil?article_id=${articleData[i]['id']}&is_up=${articleData[i]['is_up']}&is_down=${articleData[i]['is_down']}&down_count=${articleData[i]['down_count']}&up_count=${articleData[i]['up_count']}');
                      
                              // Get.find<HTTPS>().postData('/bbs/updown', {
                              //   "article_id": articleData[i]['id'],
                              //   "type": 1,
                              // });
                            },
                            child: Row(
                              children: [
                                Image.asset(
                                     'static/images/chat.png',
                                  width: 15,
                                ),
                                Text('${articleData[i]['comment_count']}'),
                              ],
                            ),
                          ),
                        ]),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: 10),
                    height: 10,
                    color: Color(0xfff3f3f3),
                  )
                ],
              ),
          ],
        ));
  }
}

class Card extends StatelessWidget {
  const Card({super.key});

  @override
  Widget build(BuildContext context) {
    final totalw = MediaQuery.of(context).size.width;

    return Container(
      margin: EdgeInsets.only(left: 15, right: 15),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(top: 15, bottom: 5),
            alignment: Alignment.centerLeft, // 确保文本左对齐
            child: Text(
              '热门话题',
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: 14,
              ),
            ),
          ),
          Obx(
            () => Wrap(
              spacing: 15,
              runSpacing: 15,
              children: [
                for (int i = 0; i < hotTopicData.length; i++)
                if(i<5)
                  GestureDetector(
                    onTap: () => {Get.toNamed('/talk/talk_info?id=${hotTopicData[i]['id']}')},
                    child: Container(
                      width: totalw / 2 - 25,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(10),
                        color: Color(0xfff5f5f5), // 卡片背景色
                        boxShadow: [
                          BoxShadow(
                            color: Colors.grey.withOpacity(0.2),
                            spreadRadius: 1,
                            blurRadius: 5,
                            offset: Offset(0, 2),
                          ),
                        ],
                      ),
                      child: Padding(
                        padding: EdgeInsets.all(8),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              children: [
                                Text(
                                  '# ',
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Color(0xFF6A3BD9),
                                  ),
                                ),
                                Text(

                                  hotTopicData[i]['topic_title'].length>8?
'${hotTopicData[i]['topic_title'].substring(0,8)}...':
                                  '${hotTopicData[i]['topic_title'].length}',
                                  style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    color: Color(0xFF333333),
                                  ),
                                ),
                              ],
                            ),
                            SizedBox(height: 4),
                            Text(
                              '${hotTopicData[i]['count']}条内容',
                              style: TextStyle(color: Colors.grey),
                            ),
                          ],
                        ),
                      ),
                    ),
                  )
,

                if(hotTopicData.length==1||hotTopicData.length==3)
                Container(
                  width: totalw / 2 - 25,
                )


              ],
            ),
          )
        ],
      ),
    );
  }
}

class SearchBar extends StatelessWidget {
  const SearchBar({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 375.0,
      margin: EdgeInsets.only(left: 15, right: 15),
      height: 40.0, // 固定总高度为40dp
      decoration: BoxDecoration(
        color: Colors.grey[200],
        borderRadius: BorderRadius.circular(20.0), // 圆角调整为高度的一半
      ),
      child: Padding(
        padding: EdgeInsets.symmetric(horizontal: 16.0), // 左右内边距
        child: Row(
          crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中
          children: [
            Icon(
              Icons.search,
              color: Colors.grey,
              size: 20.0, // 缩小图标尺寸
            ),
            SizedBox(width: 8.0),
            Expanded(
              child: TextField(
                decoration: InputDecoration(
                  hintText: '搜动态/话题/用户',
                  hintStyle: TextStyle(color: Colors.grey, fontSize: 14),
                  border: InputBorder.none,
                  isDense: true, // 关键！减少TextField默认高度
                  contentPadding: EdgeInsets.zero, // 移除内边距
                ),
                style: TextStyle(fontSize: 14.0), // 统一字体大小
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class TopDynamic extends StatelessWidget {
  TopDynamic({super.key});

  List<Map> items = const [
    {'text': "关注", "index": 0},
    {'text': "动态", "index": 1},
    {'text': "任务", "index": 2},
  ];

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(left: 15, right: 15, bottom: 5),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Row(
            children: [
              for (var item in items)
                Container(
                  margin: EdgeInsets.only(right: 8),
                  child: Stack(
                    children: [
                      Positioned(
                        right: 0, // 右偏移量
                        top: 0, // 上偏移量
                        child: ClipOval(
                          child: Container(
                            color: Color(0XFFFFFFFF), // 圆形的颜色
                            height: 4.0, // 圆的直径
                            width: 4.0, // 圆的直径
                          ),
                        ),
                      ),
                      Column(
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          GestureDetector(
                            onTap: () => {
                              articleData.value = [],
                              articlePage.value = 1,
                              if (item['index'] == 0)
                                {getFollowArticle()}
                              else if (item['index'] == 1)
                                {getArticle(), gethotTopic()}
                              else
                                {},
                              _index.value = item['index'],
                              followPage.value = 1,
                              articlePage.value = 1
                            },
                            child: Obx(
                              () => Text(item['text'],
                                  style: TextStyle(
                                      color: _index.value == item['index']
                                          ? Color(0xFF6A3BD9)
                                          : Color(0xFF999999),
                                      fontSize: 20)),
                            ),
                          ),
                          Obx(
                            () => Container(
                              height: 2, // 下划线高度
                              width: 10, // 自定义宽度（比文字长）
                              color: _index.value == item['index']
                                  ? Color(0xFF6A3BD9)
                                  : Color(0xFFffffff),
                              margin: EdgeInsets.only(top: 3), // 与文字间距
                            ),
                          )
                        ],
                      ),
                    ],
                  ),
                ),
            ],
          ),
          Row(
            children: [
              Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(20),
                ),
                padding: EdgeInsets.all(8),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.end,
                  children: [
                    Stack(
                      children: [
                        Positioned(
                          right: 0, // 右偏移量
                          top: 0, // 上偏移量
                          child: ClipOval(
                            child: Container(
                              color: Colors.red, // 圆形的颜色
                              height: 4.0, // 圆的直径
                              width: 4.0, // 圆的直径
                            ),
                          ),
                        ),
                        GestureDetector(
                          onTap: () => {Get.toNamed('/talk/notice')},
                          child: Icon(
                            Icons.notifications_none,
                            size: 28,
                            color: const Color.fromRGBO(51, 51, 51, 1),
                          ),
                        )
                      ],
                    ),
                    SizedBox(width: 16),
                    Container(
                        height: 28,
                        padding: EdgeInsets.only(top: 2, bottom: 3),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          borderRadius: BorderRadius.circular((15)),
                          gradient: LinearGradient(
                            colors: [
                              Color(0xff2189E7),
                              Color(0xffBF67F8),
                            ], // 定义颜色列表
                            begin: Alignment.topLeft, // 渐变开始的位置
                            end: Alignment.bottomRight, // 渐变结束的位置
                          ),
                        ),
                        width: 65,
                        child: GestureDetector(
                          onTap: () => {Get.toNamed('/talk/publish')},
                          child: Text('发动态',
                              style: TextStyle(
                                  fontSize: 16, color: Color(0xffffffff))),
                        )),
                  ],
                ),
              )
            ],
          ),
        ],
      ),
    );
  }
}



class GalleryView extends StatefulWidget {
  final List<dynamic> images;
  final int initialIndex;

  const GalleryView({
    super.key,
    required this.images,
    this.initialIndex = 0,
  });

  @override
  State<GalleryView> createState() => _GalleryViewState();
}

class _GalleryViewState extends State<GalleryView> {
  late int currentIndex;
  late PageController pageController;

  @override
  void initState() {
    super.initState();
    currentIndex = widget.initialIndex;
    pageController = PageController(initialPage: widget.initialIndex);
  }

  @override
  Widget build(BuildContext context) {
     final totalHeight = MediaQuery.of(context).size.height-100;
    return Scaffold(
      backgroundColor: Colors.black,
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back, color: Colors.white),
          onPressed: () => Navigator.pop(context),
        ),
      ),
      body: Stack(
        children: [
          Container(
            height: totalHeight,
            child: PhotoViewGallery.builder(
            pageController: pageController,
            itemCount: widget.images.length,
            onPageChanged: (index) => setState(() => currentIndex = index),
            builder: (context, index) {
              return PhotoViewGalleryPageOptions(
                imageProvider: NetworkImage(widget.images[index]),
                heroAttributes: PhotoViewHeroAttributes(tag: 'image$index'),
              );
            },
          ),
          )
          ,
          Positioned(
            bottom: 20,
            left: 0,
            right: 0,
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: widget.images.map((url) {
                int index = widget.images.indexOf(url);
                return Container(
                  width: 8,
                  height: 8,
                  margin: const EdgeInsets.symmetric(horizontal: 4),
                  decoration: BoxDecoration(
                    shape: BoxShape.circle,
                    color: currentIndex == index 
                      ? Colors.white 
                      : Colors.white54,
                  ),
                );
              }).toList(),
            ),
          ),
        ],
      ),
    );
  }
}